﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CPETwit.Data.Entity;
using CPETwit.Web.Service.Implementation;
using CPETwit.Web.Service.Interface;

namespace CPETwit.Web.Pages
{
    /// <summary>
    /// Description résumée de ImgHandler
    /// </summary>
    public class ImgHandler : IHttpHandler
    {
        public byte[] imageData;

        public void ProcessRequest(HttpContext context)
        {
            string login = context.Request.QueryString["login"];
            if (!String.IsNullOrEmpty(login))
            {
                TwitterService tw = new TwitterService();
                User u = tw.GetUser(login);
                if (u != null)
                {
                    this.imageData = u.avatar;
                }
                if (this.imageData != null)
                {
                    context.Response.ContentType = "image/jpeg";
                    context.Response.OutputStream.Write(this.imageData, 0, this.imageData.Length);
                    context.Response.End();
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}